@echo off
chcp 65001 > nul
setlocal enabledelayedexpansion

set "script_dir=.\python"
set "js_dir=.\zjs"
set "python_executable=python"
set "node_executable=node"

echo 可用的Python/JS脚本:
set i=0
for %%a in ("%script_dir%\*.py") do (
  set /a i+=1
  echo !i!. %%a
)
for %%a in ("%js_dir%\*.js") do (
  set /a i+=1
  echo !i!. %%a
)

REM 记录脚本路径和类型
setlocal disableDelayedExpansion
set i=0
(for %%a in ("%script_dir%\*.py") do (
  set /a i+=1
  echo py;%%a
)
for %%a in ("%js_dir%\*.js") do (
  set /a i+=1
  echo js;%%a
)) > scriptlist.txt
setlocal enabledelayedexpansion

:选择脚本
set /p "choice=请选择要运行的脚本序号: "

set "script_to_run="
set "script_type="
set i=0
for /f "tokens=1,2 delims=;" %%b in (scriptlist.txt) do (
  set /a i+=1
  if !i! equ !choice! (
    set "script_type=%%b"
    set "script_to_run=%%c"
    goto :运行脚本
  )
)

echo.
echo 选择无效，请重新选择
goto :选择脚本

:运行脚本
if "%script_type%"=="py" (
  echo 正在运行 %script_to_run%...
  %python_executable% "%script_to_run%"
) else if "%script_type%"=="js" (
  echo 正在运行 %script_to_run%...
  %node_executable% "%script_to_run%"
) else (
  echo 未知脚本类型
)
pause

del scriptlist.txt
endlocal